<script lang="ts" setup name="Son2">
    import { onUnmounted, ref } from 'vue';
    import emitter from '@/utils/emitter';

    let computer = ref('惠普 暗影精灵8 GTX4080');
    let brotherToy = ref('');
    emitter.on('send-toy', (value: any) => {
        brotherToy.value = value
    });

    // 在组件卸载时，把前面绑定的事件解绑。如果不解绑，当本组件卸载后，前面绑定的事件还在内存里，这里对内存不友好。
    onUnmounted(() => {
        emitter.off('send-toy');
    });
</script>

<template>
    <div class="son">
        <h3>子组件2</h3>
        <p>电脑：{{ computer }}</p>
    </div>
</template>

<style scoped>
    .son {
        background-color: skyblue;
        border-radius: 10px;
        padding: 5px 10px;
    }
</style>